/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.util.translator.lom2owl.owl;

import org.ieee.ltsc.lom.LOM;
import org.ieee.ltsc.lom.LOMUtil;

import java.io.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.RDFNode;

/**
 * 
 * Translates a LOM vocabulary item to its representation in OWL. 
 */
public class VI2STranslator extends ElementTranslatorImpl {

    private String category =
            new String();
    private String attributeName =
            new String();
    private String element =
            new String();

    /** Creates a new instance of VI2STranslator */
    public VI2STranslator(String elementCategory, String elementElement,
            String elementAttribute) {

        this.category =
                elementCategory;
        this.attributeName =
                elementAttribute;
        this.element =
                elementElement;
    }

    /**
     * This method translates a LOM vocabulary item to its representation 
     * in OWL. 
     * @param lom The metadata record
     * @param ont The ontology
     * @param inst The instance of learning Object
     * @param nsName The namespace
     * @param errorWriter The error file
     */
    public void apply(LOM lom, OntModel ont, Individual inst, String nsName,
            PrintWriter errorWriter) {


        try {

            // 1) Get the information from lom xml file



            if (category.equals("General")) {

                if (element.equals("Structure")) {
                    DatatypeProperty structureProperty =
                            ont.getDatatypeProperty(nsName + "#hasStructure");
                    String structureLOM =
                            LOMUtil.getValue(LOMUtil.getGeneralStructure(lom));

                    if (structureLOM != null) {
                        RDFNode structureValue =
                                ont.createTypedLiteral(structureLOM);
                        inst.setPropertyValue(structureProperty, structureValue);
                    }

                } else if (element.equals("AggregationLevel")) {

                    DatatypeProperty aggregationProperty =
                            ont.getDatatypeProperty(nsName +
                            "#hasAggregationLevel");
                    String aggregationLOM =
                            LOMUtil.getValue(LOMUtil.getGeneralAggregationLevel(lom));
                    if (aggregationLOM != null) {
                        RDFNode aggregationValue =
                                ont.createTypedLiteral(aggregationLOM);
                        inst.setPropertyValue(aggregationProperty,
                                aggregationValue);

                    }

                }

            } else if (category.equals("LifeCycle")) {
                if (element.equals("Status")) {
                    DatatypeProperty statusProperty =
                            ont.getDatatypeProperty(nsName + "#hasStatus");
                    String statusLOM =
                            LOMUtil.getValue(LOMUtil.getLifeCycleStatus(lom));

                    if (statusLOM != null) {
                        RDFNode statusValue =
                                ont.createTypedLiteral(statusLOM);
                        inst.setPropertyValue(statusProperty, statusValue);
                    }
                }
            } else if (category.equals("Rights")) {
                if (element.equals("Cost")) {
                    boolean costLOM;

                    DatatypeProperty costProperty =
                            ont.getDatatypeProperty(nsName + "#hasCost");

                    String aux =
                            LOMUtil.getValue(LOMUtil.getRightsCost(lom));
                    if (aux != null) {
                        if (aux.equals("yes")) {
                            costLOM =
                                    true;
                        } else {
                            costLOM =
                                    false;
                        }

                        RDFNode costValue =
                                ont.createTypedLiteral(costLOM);
                        inst.setPropertyValue(costProperty, costValue);
                    }
                } else if (element.equals("CopyrightAndOtherRestrictions")) {
                    boolean copyrightLOM;

                    DatatypeProperty copyrightProperty =
                            ont.getDatatypeProperty(nsName +
                            "#hasCopyrightRestrictions");

                    String aux =
                            LOMUtil.getValue(LOMUtil.getRightsCopyrightAndOtherRestrictions(lom));
                    if (aux != null) {
                        if (aux.equals("yes")) {
                            copyrightLOM =
                                    true;
                        } else {
                            copyrightLOM =
                                    false;
                        }

                        RDFNode copyrightValue =
                                ont.createTypedLiteral(copyrightLOM);
                        inst.setPropertyValue(copyrightProperty, copyrightValue);
                    }

                }

            }

        } catch (Throwable t) {
            t.printStackTrace();
            return;
        }
    }
}


